package de.openlaboratory.elib.utilities;

import java.util.Enumeration;

import javax.servlet.ServletRequest;

import org.apache.velocity.VelocityContext;
import org.apache.velocity.tools.generic.DateTool;
import org.apache.velocity.tools.view.ParameterTool;

public class ContextHelper
{
	public static void buildContext(VelocityContext context, ServletRequest request)
	{
		// add Velocity Tools to Context
		
		// * DateTool
		DateTool dateTool = new DateTool(); 
		context.put("date",dateTool);
		
		// * RequestTool
		request.setAttribute("oo", "vcr");

		ParameterTool requestTool = new ParameterTool();
		requestTool.setRequest(request);
		context.put("params",requestTool);
		
		Enumeration attrs = request.getAttributeNames();
		String attr;
		
		while (attrs.hasMoreElements())
		{
			attr = attrs.nextElement().toString();
			context.put(attr, request.getAttribute(attr));
		}
	}

}
